import requests
##注意headers里面的值要更换
headers ={"Cookie": "channel_from_id=5003605267; userid=1673091649; websid=3252538115; liveCheck=1; watched=552134599; _ga=GA1.2.1484094230.1623847549; _gid=GA1.2.2094857427.1624017068; _gat=1; kw_token=C536P4HYFK5; Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1624052337,1624052618,1624055597,1624056774; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1624056774",
          "csrf":"C536P4HYFK5",
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36 Edg/91.0.864.48"}
def Index(page):
    url = "http://www.kuwo.cn/api/www/bang/bang/musicList?bangId=16&pn={}&rn=30&httpsStatus=1".format(page)
    res = requests.get(url,headers=headers).json()
    data = res['data']['musicList']
    for i in data :
        musicrid = i['musicrid'].split('_')[1]
        musicurl = 'http://kuwo.cn/url?format=mp3&rid={}&response=url&type=convert_url3&br=128kmp3&from=web&t=1624052797462&httpsStatus=1'.format(musicrid)
        title = i['album']
        MusicList(musicurl,title)
def MusicList(musicurl,title):
    try:
        res = requests.get(musicurl,headers=headers).json()
        url = res['url']
        music = requests.get(url,headers=headers)
        with open('./music/'+title+'.mp3',"ab") as f :
            f.write(music.content)
            print("{}下载完成......".format(title+'.mp3'))
    except:
        pass

if __name__ == '__main__':
        for page in range(1,9):

            Index(page)